import xFetch from './xFetch';

export async function getSubTree() {
  return xFetch('/api/subject/subTree', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function subSelectTree() {
  return xFetch('/api/subject/subSelectTree', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getSubjectContent(id, type) {
  return xFetch('/api/subject/' + id + '/' + type, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getSubjectContentTree(id) {
  return xFetch('/api/subject/' + id + '/contentTree', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getImage() {
  return xFetch('/api/hive/image', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getStatusImage(status) {
  return xFetch('/api/hive/image/status/' + status, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getImageInfo(id) {
  return xFetch('/api/hive/image/' + id, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getColumns(id) {
  return xFetch('/api/hive/columns/' + id, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getSubAll() {
  return xFetch('/api/subject/all', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getCatBySubId(subId) {
  return xFetch('/api/category/categorys/' + subId, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getCatByCatId(catId) {
  return xFetch('/api/category/' + catId, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function addSub(subs) {
  return xFetch('/api/subject/add', {
    method: 'POST',
    body: JSON.stringify(subs),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function addCat(cats) {
  return xFetch('/api/category/addToSub', {
    method: 'POST',
    body: JSON.stringify(cats),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function updateSub(sub) {
  return xFetch('/api/subject/update', {
    method: 'PUT',
    body: JSON.stringify(sub),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function updateCat(cat) {
  return xFetch('/api/category/update', {
    method: 'PUT',
    body: JSON.stringify(cat),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function deleteSub(id) {
  return xFetch('/api/subject/' + id, {
    method: 'DELETE',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function deleteCat(id) {
  return xFetch('/api/category/' + id, {
    method: 'DELETE',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function getTableList(id) {
  return xFetch('/api/category/' + id + '/tables', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getTableInfo(id) {
  return xFetch('/api/table/' + id, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function updateTableMeta(tInfo) {
  return xFetch('/api/table/updateTableMeta', {
    method: 'PUT',
    body: JSON.stringify(tInfo),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function updateRemCom(tInfo) {
  return xFetch('/api/table/updateRemCom', {
    method: 'PUT',
    body: JSON.stringify(tInfo),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function subBind(data) {
  return xFetch('/api/relation/subBind', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function catBind(data) {
  return xFetch('/api/relation/catBind', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function subUnBind(data) {
  return xFetch('/api/relation/subUnBind', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function catUnBindTab(data) {
  return xFetch('/api/relation/catUnBindTab', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function search(type, key) {
  return xFetch('/api/search/' + type + '/' + key, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function dbConfirm(id) {
  return xFetch('/api/hive/dbConfirm/' + id, {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function tableConfirm(id) {
  return xFetch('/api/hive/tableConfirm/' + id, {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function columnConfirm(id) {
  return xFetch('/api/hive/columnConfirm/' + id, {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

